package xyz.canran.tool.action;

import xyz.canran.tool.body.CreateProjectBody;

import java.io.File;
import java.util.Map;

public class ProjectAction {

    public static boolean createProject(CreateProjectBody body) {
        String projectName = body.getProjectName();
        String projectParentPath = body.getProjectParentPath();
        File parentFile = new File(projectParentPath);
        if (!parentFile.exists()) {
            boolean mkdirResult = parentFile.mkdirs();
            if (!mkdirResult) {
                System.err.println("创建项目父目录失败！");
                throw new RuntimeException("创建项目父目录失败！" + projectParentPath);
            }
        }

        String jdkVersion = body.getJdkVersion();
        String groupId = body.getGroupId();
        String artifactId = body.getArtifactId();
        String version = body.getVersion();
        String packageName = body.getPackageName();
        boolean extendSpringBootStarterParent = body.isExtendSpringBootStarterParent();
        //TODO 如果是继承自Spring Boot项目还是不继承Spring Boot项目使用依赖管理
        if (extendSpringBootStarterParent) {

        }
        boolean multiModuleProject = body.isMultiModuleProject();

        Map<String, Object> projectStructTree = body.getProjectStructTree();
        if (!multiModuleProject) {
            // TODO 单模块项目直接生成目录和pom.xml对应jar项目

        } else {
            // TODO 解析树形结构生成目录和pom.xml中模块
        }

        return true;
    }
}
